﻿//=============================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：孙德响
// 日 期：2012-1-11
// 描 述: 一推讲师演讲总结
//
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00   2012/1/11    孙德响           
//=============================================================
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.DBModule;
using ZX.BLL.Extend;
using ZX.EHR.Library;
using ZX.CRM.Bussiness;
using ZX.SYS.Library;
using ZX.CRM.Library;
using ZX.BLL;
using ZX.Common; 

namespace ZX.WebApp.Crm.Sale
{
    public partial class AddTeachSumup : EditUIPage
    {
        BCrmTeachSumup Bbussness = new BCrmTeachSumup();  //业务处理类
        protected void Page_Load(object sender, EventArgs e)
        {

            //string strEntity = "V_CrmTeachSumup";
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ZX.WebApp.Crm.Sale.AddTeachSumup));
            string id = this.GetStringFromQueryString("ID", "");        //课程活动的主键 
            //BaseEntity instance = ZX.Common.Globals.getEntity(strEntity) as BaseEntity;
            //BaseBussnies bInstance = new BLL.Extend.BaseBussnies(instance);
            //BaseEntity entity = bInstance.GetEntityById(id) as BaseEntity;
            //this.EditTemplate.Text = CreateHtml(instance, entity);

            Bbussness.entity = new DatPhraseDetail();
            IList<DatPhraseDetail> ListTypeId = Bbussness.GetDatPhraseDetailByClassId(new Guid("d57fa4b9-3fa0-4f42-aa45-a6febe889fdc"));
            if (ListTypeId != null && ListTypeId.Count > 0)
            {
                this.DDlJWX.DataSource = ListTypeId;
                this.DDlJWX.DataTextField = "PhraseText";
                this.DDlJWX.DataValueField = "PhraseID";
                this.DDlJWX.DataBind();
            }
            
            SetValue(id);     
        }
        /// <summary>
        /// 赋值
        /// </summary>
        /// <param name="ID"> 讲师行程ID</param>
        public bool  SetValue(string ID)
        {
            Bbussness.entity = new V_CrmTeachSumup();
            IList<V_CrmTeachSumup> LVCrmTeachSumup = Bbussness.GetEntitys<V_CrmTeachSumup>("ThodometerId='" + ID + "'");
            if (LVCrmTeachSumup == null)
            {
                type.Value = "0";
                Bbussness.entity = new V_CrmTeachHodometer();
                V_CrmTeachHodometer TeachHodometer = (V_CrmTeachHodometer)Bbussness.GetEntityById(ID);
                if (TeachHodometer == null)
                {
                    return false;
                }
                else
                {
                    Date.Value = TeachHodometer.HmDate.ToString("yyyy-MM-dd");
                    TeachPlace.Value = TeachHodometer.EXP1;
                    HmtypeID.SelectedValue = TeachHodometer.HmType.ToString();
                    Bbussness.entity = new V_CrmCustomer();
                    V_CrmCustomer Vcrmcustomer = (V_CrmCustomer)Bbussness.GetEntityById(TeachHodometer.CusID.ToString());
                    if (Vcrmcustomer != null)
                    {
                        CustomerCode.Value = Vcrmcustomer.Code;
                        CustomerName.Value = Vcrmcustomer.CustomerName;
                        Username.Value = Vcrmcustomer.UName;
                        SaleName.Value = Vcrmcustomer.SaleadName;
                        Address.Value = Vcrmcustomer.State + Vcrmcustomer.Province + Vcrmcustomer.City + Vcrmcustomer.Area + Vcrmcustomer.Address;
                        Tradename.Value = Vcrmcustomer.CustomerTrade;
                        PersonSum.Value = Vcrmcustomer.PersonSum.ToString();
                        ProductSum.Value = Vcrmcustomer.ProductSum.ToString();
                        CompanyGain.Value = Vcrmcustomer.CompanyGain.ToString();
                        #region  ========2012/2/28新增=========
                        Homeplace.Value = Vcrmcustomer.Homeplace.ToString();
                        RbBirthdayType.SelectedValue = Vcrmcustomer.BirthdayType.ToString();
                        if (Vcrmcustomer.DecisionBirthday.ToString("yyyy-MM-dd") != "1900-01-01")
                        { 
                            DecisionBirthday.Value = Vcrmcustomer.DecisionBirthday.ToString("yyyy-MM-dd");
                        }
                        Character.Value = Vcrmcustomer.Character.ToString();
                        SchoolScientifc.Value = Vcrmcustomer.SchoolScientifc.ToString();
                        DecisionFancy.Value = Vcrmcustomer.DecisionFancy.ToString();
                        Credit.Value = Vcrmcustomer.Credit.Trim().ToString();
                        Pullulation.Value = Vcrmcustomer.Pullulation.Trim().ToString();
                        if (Vcrmcustomer.CompanyCreateDate.ToString("yyyy-MM-dd") != "1900-01-01")
                        {
                            CompanyCreateDate.Value = Vcrmcustomer.CompanyCreateDate.ToString("yyyy-MM-dd");
                        }
                        PersonSum.Value = Vcrmcustomer.PersonSum.ToString();
                        ProductSum.Value = Vcrmcustomer.ProductSum.ToString();
                        CompanyGain.Value = Vcrmcustomer.CompanyGain.ToString();
                        DecisionPersonsun.Value = Vcrmcustomer.DecisionPersonsun.ToString();
                        HighPersonsum.Value = Vcrmcustomer.HighPersonsum.ToString();
                        MiddlePersonsum.Value = Vcrmcustomer.MiddlePersonsum.ToString();
                        BelowPersonsum.Value = Vcrmcustomer.BelowPersonsum.ToString();
                        TrainCompany.Value = Vcrmcustomer.TrainCompany.ToString();
                        if (Vcrmcustomer.TrainDate.ToString("yyyy-MM-dd") != "1900-01-01")
                        {
                            TrainDate.Value = Vcrmcustomer.TrainDate.ToString("yyyy-MM-dd");
                        }
                        TrainHistory.Value = Vcrmcustomer.TrainHistory.ToString();
                        CustomerPhylogeny.Value = Vcrmcustomer.CustomerPhylogeny.ToString();
                        Painful.Value = Vcrmcustomer.Painful.ToString();
                        AffectDecisioner.Value = Vcrmcustomer.AffectDecisioner.ToString();
                        #endregion

                    }
                    Bbussness.entity = new V_CrmCustomerOrder();
                    IList<V_CrmCustomerOrder> lcrmcustomerorder = Bbussness.GetOrderDetail(TeachHodometer.CusID);
                    if (lcrmcustomerorder != null)
                    {

                        this.DDLOrder.DataSource = lcrmcustomerorder;
                        this.DDLOrder.DataTextField = "Code";
                        this.DDLOrder.DataValueField = "ID";
                        this.DDLOrder.DataBind();
                    }
                    return true;
                }
                
            }
            else
            {
                #region ================更新演讲总结======================
                try
                {
                     V_CrmTeachSumup VCrmTeachSumup=  LVCrmTeachSumup[0];
                     if (VCrmTeachSumup.HmDate.ToString("yyyy-MM-dd") != "1900-01-01")
                     {
                         Date.Value = VCrmTeachSumup.HmDate.ToString("yyyy-MM-dd");
                     }
                    TeachPlace.Value = VCrmTeachSumup.EXP1;
                    HmtypeID.SelectedValue = VCrmTeachSumup.HmType.ToString();
                    CustomerCode.Value = VCrmTeachSumup.CustomerCode;
                    CustomerName.Value = VCrmTeachSumup.CustomerName;
                    Username.Value = VCrmTeachSumup.AddUserName; ;
                    SaleName.Value = VCrmTeachSumup.SaleadviserName;
                    Address.Value = VCrmTeachSumup.Address;
                    Tradename.Value = VCrmTeachSumup.TradeName;
                    this.DDLOrder.DataSource = LVCrmTeachSumup;
                    this.DDLOrder.DataTextField = "OrderCode";
                    this.DDLOrder.DataValueField = "OrderId";
                    this.DDLOrder.DataBind();
                    RbGripe.SelectedValue = VCrmTeachSumup.IsGripe;
                    RbClass.SelectedValue = VCrmTeachSumup.IsClass;
                    RbBargain.SelectedValue = VCrmTeachSumup.IsBargain;
                    DDLOrder.SelectedValue = VCrmTeachSumup.OrderId.ToString();
                    RbValue.SelectedValue = VCrmTeachSumup.IsValue;
                    RbStandard.SelectedValue = VCrmTeachSumup.IsStandard;
                    DDlJWX.SelectedValue = VCrmTeachSumup.JWXID.ToString();
                    UserID.Value = VCrmTeachSumup.TutorId.ToString();
                    if (VCrmTeachSumup.UName != null)
                    { txtUserID.Value = VCrmTeachSumup.UName; }
                    GripeExplain.Value = VCrmTeachSumup.GripeExplain;
                    if (VCrmTeachSumup.ClassExplain.Trim().Length > 0)
                    {
                        if (Convert.ToDateTime(VCrmTeachSumup.ClassExplain).ToString("yyyy-MM-dd") != "1900-01-01")
                        {
                            ClassExplain.Value = Convert.ToDateTime(VCrmTeachSumup.ClassExplain).ToString("yyyy-MM-dd");
                        }
                    }
                    Explain.Value = VCrmTeachSumup.Explain;
                    DeptID.Value = VCrmTeachSumup.DeptId.ToString();
                    txtDeptID.Value = VCrmTeachSumup.DeptName;
                    type.Value = "1";
                    Teachsumupid.Value = VCrmTeachSumup.ID.ToString();
                    CustomerPromis.Value = VCrmTeachSumup.CustomerPromis.ToString();
                    PersonSum.Value = VCrmTeachSumup.PersonSum.ToString();
                    ProductSum.Value = VCrmTeachSumup.ProductSum.ToString();
                    CompanyGain.Value = VCrmTeachSumup.CompanyGain.ToString();
                    Painful.Value = VCrmTeachSumup.Painful.ToString();
                    Pullulation.Value = VCrmTeachSumup.Pullulation.ToString();
                    TrainHistory.Value = VCrmTeachSumup.TrainHistory.ToString();
                    #region  ========2012/2/28新增=========
                    Homeplace.Value = VCrmTeachSumup.Homeplace.ToString();
                    RbBirthdayType.SelectedValue = VCrmTeachSumup.BirthdayType.ToString();
                    if (VCrmTeachSumup.DecisionBirthday.ToString("yyyy-MM-dd") != "1900-01-01")
                    {
                        DecisionBirthday.Value = VCrmTeachSumup.DecisionBirthday.ToString("yyyy-MM-dd");
                    }
                    Character.Value = VCrmTeachSumup.Character.ToString();
                    SchoolScientifc.Value = VCrmTeachSumup.SchoolScientifc.ToString();
                    DecisionFancy.Value = VCrmTeachSumup.DecisionFancy.ToString();
                    Credit.Value = VCrmTeachSumup.Credit.ToString();
                    Pullulation.Value = VCrmTeachSumup.Pullulation.ToString();
                    if (VCrmTeachSumup.CompanyCreateDate.ToString("yyyy-MM-dd") != "1900-01-01")
                    {
                        CompanyCreateDate.Value = VCrmTeachSumup.CompanyCreateDate.ToString("yyyy-MM-dd");
                    }
                    PersonSum.Value = VCrmTeachSumup.PersonSum.ToString();
                    ProductSum.Value = VCrmTeachSumup.ProductSum.ToString();
                    CompanyGain.Value = VCrmTeachSumup.CompanyGain.ToString();
                    DecisionPersonsun.Value = VCrmTeachSumup.DecisionPersonsun.ToString();
                    HighPersonsum.Value = VCrmTeachSumup.HighPersonsum.ToString();
                    MiddlePersonsum.Value = VCrmTeachSumup.MiddlePersonsum.ToString();
                    BelowPersonsum.Value = VCrmTeachSumup.BelowPersonsum.ToString();
                    TrainCompany.Value = VCrmTeachSumup.TrainCompany.ToString();
                    if (Convert.ToDateTime(VCrmTeachSumup.TrainDate).ToString("yyyy-MM-dd") != "1900-01-01")
                    {
                        TrainDate.Value = Convert.ToDateTime(VCrmTeachSumup.TrainDate).ToString("yyyy-MM-dd");
                    }
                    TrainHistory.Value = VCrmTeachSumup.TrainHistory.ToString();
                    CustomerPhylogeny.Value = VCrmTeachSumup.CustomerPhylogeny.ToString();
                    Painful.Value = VCrmTeachSumup.Painful.ToString();
                    BargainDispute.Value = VCrmTeachSumup.BargainDispute.ToString();
                    BargainReason.Value = VCrmTeachSumup.BargainReason.ToString();
                    AffectDecisioner.Value = VCrmTeachSumup.AffectDecisioner.ToString();
                    BargainNum.Value = VCrmTeachSumup.BargainNum.ToString();
                    #endregion
                }
                catch
                {
 
                }
                #endregion
            }
            return true;
        }
        [AjaxPro.AjaxMethod]
        public string  Save(string Parmstr)
        {
            string  returnint = "保存失败";
            try
            {
                //itype
                if (Parmstr.Split('︽').Length != 4)
                {
                    returnint = "参数传递有误!";
                    return returnint;
                }
                string id = Parmstr.Split('︽')[1];        //课程活动的主键 
                string TeachSumups = Parmstr.Split('︽')[0];        //课程活动的主键 
                string type = Parmstr.Split('︽')[2];        //课程活动的主键 
                DatUser du = (DatUser)System.Web.HttpContext.Current.Session["User"]; //用户ID
                if (du == null)
                {
                    returnint="当前用户信息出现异常！";
                    return returnint;
                }
                if (TeachSumups.Split('︾').Length == 40)
                {
                    Bbussness.entity = new CrmTeachSumup();
                    V_CrmTeachSumup TeachSumup = new V_CrmTeachSumup();

                    if (TeachSumups.Split('︾')[7].Trim().Length > 0)
                    {
                        TeachSumup.TutorId = new Guid(TeachSumups.Split('︾')[7]);
                    }

                    if (TeachSumups.Split('︾')[35].Trim().Length > 500)
                    {                    

                        returnint = "成交原因字数不可以大于500！";
                        return returnint;
                    }

                    if (TeachSumups.Split('︾')[36].Trim().Length > 500)
                    {
                        returnint = "成交抗拒点字数不可以大于500！";
                        return returnint;
                    }

                    if (TeachSumups.Split('︾')[13].Trim().Length > 100)
                    {
                        returnint = "对客户的承诺字数不可以大于100！";
                        return returnint;
                    }
                    if (TeachSumups.Split('︾')[9].Trim().Length > 0)
                    {
                        try
                        {
                            DateTime test = Convert.ToDateTime(TeachSumups.Split('︾')[9]);
                        }
                        catch
                        {
                            returnint = "预计上课时间请输入时间格式！";
                            return returnint;


                        }
                    }
                    if (TeachSumups.Split('︾')[22].Trim().Length > 0)
                    {
                        try
                        {
                            DateTime test = Convert.ToDateTime(TeachSumups.Split('︾')[22]);
                        }
                        catch
                        {
                            returnint = "决策人生日请输入时间格式！";
                            return returnint;
                        }
                    }
                    try
                    {
                        DateTime test = Convert.ToDateTime(TeachSumups.Split('︾')[27]);
                    }
                    catch
                    {
                        returnint = "成立日期请输入时间格式！";
                        return returnint;
                    }
                    try
                    {
                        int personsum = Convert.ToInt32(TeachSumups.Split('︾')[14]);
                    }
                    catch
                    {
                        returnint = "员工人数请输入整数格式！";
                        return returnint;
                    }

                    try
                    {
                        float personsum = Convert.ToInt32(TeachSumups.Split('︾')[15]);
                    }
                    catch
                    {
                       
                        returnint = "企业产值请输入数字格式！";
                        return returnint;
                    }
                    try
                    {
                        int test = Convert.ToInt32(TeachSumups.Split('︾')[14]);
                    }
                    catch
                    {                       
                        returnint = "企业人数请输入数字！";
                        return returnint;
                    }
                    try
                    {
                        int test = Convert.ToInt32(TeachSumups.Split('︾')[38]);
                    }
                    catch
                    {
                        returnint = "成交家数必须是整数！";
                        return returnint;
                    }
                    TeachSumup.IsGripe = TeachSumups.Split('︾')[0].Trim();
                    TeachSumup.IsClass = TeachSumups.Split('︾')[1].Trim();
                    TeachSumup.IsBargain = TeachSumups.Split('︾')[2].Trim();
                    TeachSumup.OrderId = new Guid(TeachSumups.Split('︾')[3].Trim());
                    TeachSumup.ThodometerId = new Guid(id.Trim());
                    TeachSumup.IsStandard = TeachSumups.Split('︾')[4].Trim();
                    TeachSumup.JWXID = new Guid(TeachSumups.Split('︾')[5].Trim());
                    TeachSumup.DeptId = new Guid(TeachSumups.Split('︾')[6].Trim());
                    TeachSumup.GripeExplain = TeachSumups.Split('︾')[8].Trim();
                    TeachSumup.ClassExplain = TeachSumups.Split('︾')[9].Trim();
                    TeachSumup.Explain = TeachSumups.Split('︾')[10].Trim();
                    TeachSumup.PrelectDate = Convert.ToDateTime(TeachSumups.Split('︾')[11].Trim());
                    TeachSumup.TeachPlace = TeachSumups.Split('︾')[12].Trim();
                    TeachSumup.CustomerPromis = TeachSumups.Split('︾')[13].Trim();
                    TeachSumup.Adduser = new Guid(du.UserID.ToString().Trim());
                    TeachSumup.Addtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd").Trim());
                    TeachSumup.PersonSum = Convert.ToInt32(TeachSumups.Split('︾')[14].Trim());
                    TeachSumup.ProductSum = Convert.ToDecimal(TeachSumups.Split('︾')[15].Trim());
                    TeachSumup.CompanyGain = TeachSumups.Split('︾')[16].ToString().Trim();
                    TeachSumup.TrainHistory = TeachSumups.Split('︾')[17].ToString().Trim();
                    TeachSumup.Painful = TeachSumups.Split('︾')[18].ToString().Trim();
                    TeachSumup.Pullulation = TeachSumups.Split('︾')[19].ToString().Trim();
                    TeachSumup.Homeplace = TeachSumups.Split('︾')[20].ToString().Trim();
                    TeachSumup.BirthdayType = TeachSumups.Split('︾')[21].ToString().Trim();
                    if (TeachSumups.Split('︾')[22].ToString().Trim().Length > 0)
                    {
                        TeachSumup.DecisionBirthday = Convert.ToDateTime(TeachSumups.Split('︾')[22].ToString().Trim());
                    }
                    else
                    {
                        TeachSumup.DecisionBirthday = Convert.ToDateTime("1900-1-1");
                    }
                    TeachSumup.Character = TeachSumups.Split('︾')[23].ToString().Trim();
                    TeachSumup.SchoolScientifc = TeachSumups.Split('︾')[24].ToString().Trim();
                    TeachSumup.DecisionFancy = TeachSumups.Split('︾')[25].ToString().Trim();
                    TeachSumup.Credit = TeachSumups.Split('︾')[26].ToString().Trim();
                    TeachSumup.CompanyCreateDate = Convert.ToDateTime(TeachSumups.Split('︾')[27].ToString().Trim());
                    TeachSumup.DecisionPersonsun = Convert.ToInt32(TeachSumups.Split('︾')[28].ToString().Trim());
                    TeachSumup.HighPersonsum = Convert.ToInt32(TeachSumups.Split('︾')[29].ToString().Trim());
                    TeachSumup.MiddlePersonsum = Convert.ToInt32(TeachSumups.Split('︾')[30].ToString().Trim());
                    TeachSumup.BelowPersonsum = Convert.ToInt32(TeachSumups.Split('︾')[31].ToString().Trim());
                    TeachSumup.TrainCompany = TeachSumups.Split('︾')[32].ToString().Trim();
                    if (TeachSumups.Split('︾')[33].ToString().Length == 0)
                    {
                        TeachSumup.TrainDate = Convert.ToDateTime("1901-1-1");
                    }
                    else
                    {
                        TeachSumup.TrainDate = Convert.ToDateTime(TeachSumups.Split('︾')[33].ToString().Trim());
                    }

                    TeachSumup.CustomerPhylogeny = TeachSumups.Split('︾')[34].ToString().Trim();
                    TeachSumup.BargainReason = TeachSumups.Split('︾')[35].ToString().Trim();
                    TeachSumup.BargainDispute = TeachSumups.Split('︾')[36].ToString().Trim();
                    TeachSumup.AffectDecisioner = TeachSumups.Split('︾')[37].ToString().Trim();
                    TeachSumup.BargainNum = Convert.ToInt32(TeachSumups.Split('︾')[38].ToString().Trim());
                    TeachSumup.IsValue = TeachSumups.Split('︾')[39];
                    if (type == "0")
                    {
                        TeachSumup.ID = Guid.NewGuid();
                        returnint = Bbussness.ExecProc(TeachSumup, 0);
                    }
                    else
                    {
                        if (Parmstr.Split('︽')[3].Trim().Length > 0)
                        {
                            TeachSumup.ID = new Guid(Parmstr.Split('︽')[3]);
                            returnint=Bbussness.ExecProc(TeachSumup, 1);

                        }
                    }
                }
            }
            catch
            {
                returnint="保存失败";
            }

            return returnint;
 
        }
        public string strType
        { get { return this.GetStringFromQueryString("type",""); } }
    }
}